package com.juzi.wopu.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.juzi.wopu.domain.Employee;
import com.juzi.wopu.domain.Menu;
import com.juzi.wopu.domain.SysCode;
import com.juzi.wopu.service.IMenuService;
import com.juzi.wopu.service.ISysCodeService;

public class MainAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	
	private IMenuService menuService;
	
	private ISysCodeService sysCodeService;

	private List<SysCode> list=new ArrayList<>();
		
	public List<SysCode> getList() {
		return list;
	}
	
	public void setList(List<SysCode> list) {
		this.list = list;
	}
	
	public void setMenuService(IMenuService menuService) {
		this.menuService = menuService;
	}
	
	public ISysCodeService getSysCodeService() {
		return sysCodeService;
	}
	
	public void setSysCodeService(ISysCodeService sysCodeService) {
		this.sysCodeService = sysCodeService;
	}
	
	@Override
	public String execute() throws Exception {
		Employee loginUser=getLoginUser();
		String company=loginUser.getCompany();
		String[] cs=company.split(",");
		if(cs!=null && cs.length>0){
			Map<Long, SysCode> map=new HashMap<>();
			sysCodeService.getSysCodeMap(map,null);
			for(String s:cs){
				list.add(map.get(Long.parseLong(s)));
			}
		}
		List<Menu> menus=menuService.findByLogin(loginUser);
		putContext("menus", menus);
		return SUCCESS;
	}
	
	public String right() throws Exception {
		return "right";
	}
}
